{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-07-22 20:34:44.424\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-07-22 20:34:44,471\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-07-22 20:34:44,472\tINFO worker.py:1582 -- Calling ray.init() again after it has already been called.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This image shows a colorful illustration of many cats clustered together. The cats are depicted in various shades of orange, white, and black, creating a striking composition against a blue background. The illustration style appears to be a mix of realistic and stylized, capturing the distinctive features of different cat breeds and expressions.\n",
      "\n",
      "There are approximately 15-20 cats visible, each with unique markings and facial expressions. Some cats appear to be looking directly at the viewer, while others are gazing in different directions. The cats are arranged in a stacked or layered manner, filling the entire frame and creating a dense, eye-catching image.\n",
      "\n",
      "The artwork has a playful and charming quality, showcasing the diversity and personality of cats. There are some Chinese characters or symbols visible in the corners of the image, suggesting this might be part of an Asian art style or created by an Asian artist.\n",
      "\n",
      "Above the image, there's a code snippet visible, indicating that this image is being displayed as part of a programming output, likely using Python to process and show images from a JSON file.\n"
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "import json\n",
    "import base64\n",
    "\n",
    "llm = byzerllm.ByzerLLM.from_default_model(\"sonnet_3_5_chat\")\n",
    "\n",
    "image_data = base64.b64encode(open(\"../images/cat2.png\", \"rb\").read()).decode()\n",
    "\n",
    "v = llm.chat_oai(\n",
    "    conversations=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": json.dumps(\n",
    "                [\n",
    "                    {\"image\": f\"data:image/png;base64,{image_data}\"},\n",
    "                    {\"text\": \"what in this image?\"},\n",
    "                ],\n",
    "                ensure_ascii=False,\n",
    "            ),\n",
    "        }\n",
    "    ]\n",
    ")\n",
    "print(v[0].output)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
